<!DOCTYPE html> 
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="../doc/doc_brython.css">

<link rel="stylesheet" href="console.css">

<script src="ace/ace.js" type="text/javascript" charset="utf-8"></script>
<script src="ace/ext-language_tools.js" type="text/javascript" charset="utf-8"></script>
<script src="ace/mode-python3.js" type="text/javascript" charset="utf-8"></script>
<script src="ace/snippets/python.js" type="text/javascript" charset="utf-8"></script>


<script type="text/javascript" src="../src/brython_builtins.js"></script>
<script type="text/javascript" src="../src/version_info.js"></script>
<script type="text/javascript" src="../src/py2js.js"></script>
<script type="text/javascript" src="../src/py_object.js"></script>
<script type="text/javascript" src="../src/py_type.js"></script>
<script type="text/javascript" src="../src/py_utils.js"></script>
<script type="text/javascript" src="../src/py_sort.js"></script>
<script type="text/javascript" src="../src/py_builtin_functions.js"></script>
<script type="text/javascript" src="../src/py_exceptions.js"></script>
<script type="text/javascript" src="../src/py_range_slice.js"></script>
<script type="text/javascript" src="../src/py_bytes.js"></script>
<script type="text/javascript" src="../src/py_set.js"></script>
<script type="text/javascript" src="../src/js_objects.js"></script>
<script type="text/javascript" src="../src/stdlib_paths.js"></script>
<script type="text/javascript" src="../src/py_import.js"></script>

<script type="text/javascript" src="../src/py_string.js"></script>
<script type="text/javascript" src="../src/py_int.js"></script>
<script type="text/javascript" src="../src/py_long_int.js"></script>
<script type="text/javascript" src="../src/py_float.js"></script>
<script type="text/javascript" src="../src/py_complex.js"></script>
<script type="text/javascript" src="../src/py_dict.js"></script>
<script type="text/javascript" src="../src/py_list.js"></script>
<script type="text/javascript" src="../src/py_generator.js"></script>
<script type="text/javascript" src="../src/py_dom.js"></script>

<script type="text/javascript" src="../src/builtin_modules.js"></script>
<script type="text/javascript" src="../src/py_import_hooks.js"></script>
<script type="text/javascript" src="../src/async.js"></script>

<script type="text/javascript" src="../src/py_VFS.js"></script>

<script type="text/python3" id="tests">
import time
import sys
import traceback
import dis

from browser import document as doc, window, alert, console, prompt
from browser import timer
from browser.local_storage import storage

import editor, brython_test_utils as utils

utils.populate_testmod_input(doc['files'],
    ["Core language features", "Issues", "Modules"])

script_num = -1
failed = []
t_start = None

def run():
    global output
    doc["console"].value = ''
    src = editor.editor.getValue()
    if storage is not None:
       storage["py_src"] = src

    state, t0, t1 = utils.run(src)
    output = doc["console"].value

    print('<completed in %6.2f ms>' % ((t1 - t0) * 1000.0))
    return state

def test_next():
    global script_num,failed
    script_num += 1
    options = doc['files'].options
    if script_num < len(options):
        try:
            option = doc['files'].options[script_num]
            src = open(option.value).read()
            doc['files'].selectedIndex = script_num
            editor.editor.setValue(src)
            state = run()
            if state == 0:
                failed.append(option.text)
            timer.set_timeout(test_next,500)
        except Exception as exc:
            traceback.print_exc(file=sys.stderr)
    else:
        doc['console'].value = ''
        print('completed all tests in %.2f s' %(time.time()-t_start))
        print('failed : %s' %failed)
    
def test_all(ev):
    global script_num,failed,t_start
    script_num = -1
    t_start = time.time()
    failed = []
    test_next()

def set_debug(ev):
    if ev.target.checked:
        __BRYTHON__.debug = 1
    else:
        __BRYTHON__.debug = 0

def set_loop_timeout(ev):
    if ev.target.checked:
        timeout = prompt('Loop timeout, in seconds')
        try:
            __BRYTHON__.loop_timeout = int(timeout)
            doc['timeout_value'].text = '%s s.' %timeout
        except:
            alert('Invalid value for timeout : %s' %timeout)
    else:
        __BRYTHON__.loop_timeout = False
        doc['timeout_value'].text = ''

__BRYTHON__.debug = int(doc['set_debug'].checked)

# bindings
doc['test_all'].bind('click',test_all)
doc['set_debug'].bind('change',set_debug)

doc['show_js'].bind('click',editor.show_js)
doc['run'].bind('click',lambda ev:run())
doc['show_console'].bind('click',editor.show_console)
doc['files'].bind('change',editor.load_script)
doc['set_loop_timeout'].bind('change',set_loop_timeout)
</script>

<script type="text/python3" id="translations">
from browser import document as doc
import header
qs_lang,language = header.show()
# other translations

trans = {
    'report_bugs':{'en':'Please report bugs in the ',
                   'es':'Poner los bugs en el ',
                   'fr':"Signalez les bugs dans l'"},
    'test_page':{'en':'Tests page','es':'Página de pruebas','fr':'Page de tests'},
    'run':{'en':'run','es':'ejecutar','fr':'exécuter'},
    'clear':{'en':'clear','es':'borrar','fr':'effacer'}
}


for key in trans:
    if key in doc:
        doc[key].html = trans[key][language]
</script>

</head>

<body onload="brython({debug:1, cache:'none', static_stdlib_import:true})">

<table id=banner cellpadding=0 cellspacing=0>
<tr id=banner_row >
<td class="logo"><a href="../index.html"><img src="../brython.png" class="logo"></a></td>
</tr>
</table>

<div style="text-align:center">
<br>Brython version: <span id="version"></span>
</div>
</center>


<div id="container">
<div id="left-div">
<div style="padding: 3px 3px 3px 3px;">
Test:
<select name="filename" id="files">
</select>
<button id="test_all">Run all tests</button>

</div>
  <div id="editor" style="width:100%;"></div>
</div>

<div id="right-div">
<div style="padding: 3px 3px 3px 3px;">
  <div style="float:left">
    <button id="run">run</button>
    debug<input type="checkbox" id="set_debug" checked>
    loop timeout<input type="checkbox" id="set_loop_timeout" autocomplete="off">
    <span id="timeout_value"></span>
  </div>
  <div style="float:right">
    <button id="show_console">Show console</button>
    <button id="show_js">Show Javascript</button>
  </div>
</div>

<div style="width:100%;height:100%;">
<textarea id="console" autocomplete="off"></textarea>
</div>

<div id="timeout_dialog" title="Set timeout for loops" style="visibility:hidden">
    <form>
     <fieldset>
      <label for="loop_timeout">Timeout (sec.)</label>
      <input type="text" name="timeout" id="timeout" value="20" class="text ui-widget-content ui-corner-all">
     </fieldset>
    </form>
</div>

</div>
</div>
</body>
</html>

